package views;

import charts.PieTest;
import views.admin.AddAdminFrame;
import views.admin.AdminChangePassword;
import views.category.AllCategorys;
import views.category.Category_Update_Delete;
import views.category.JobCategoryAddFrame;
import views.employer.AllEmployers;
import views.employer.EmployerAddFrame;
import views.employer.Employer_Update_Delete;
import views.fee.employer.AllFeeEm;
import views.fee.employer.FeeEmAddFrame;
import views.fee.employer.FeeEm_Update_Delete;
import views.fee.seeker.AllFeeSeeker;
import views.fee.seeker.FeeSeekerAddFrame;
import views.fee.seeker.FeeSeeker_Update_Delete;
import views.job.AllJobs;
import views.job.JobAddFrame;
import views.job.Job_Update_Delete;
import views.seeker.AllSeekers;
import views.seeker.SeekerAddFrame;
import views.seeker.Seeker_Update_Delete;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 管理员登陆后的主界面
 */
public class SystemRootFrame extends JFrame {
    public static int ADMIN_ACCOUNT;
    ImageIcon imageIcon = new ImageIcon("src/images/manage.png");

    public SystemRootFrame() {
        this.setLayout(null);
        ImageIcon img = new ImageIcon("src/images/main.jpg");
        //要设置的背景图片
        JLabel imgLabel = new JLabel(img);
        imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
        //将背景图放在标签里。
        this.getLayeredPane().add(imgLabel, Integer.valueOf(Integer.MIN_VALUE));
        //将背景标签添加到jfram的LayeredPane面板里。
        // 设置背景标签的位置
        Container contain = this.getContentPane();
        ((JPanel) contain).setOpaque(false);

        setSize(1000, 730);
        setTitle("职业介绍管理系统");
        setIconImage(imageIcon.getImage().getScaledInstance(80, 80, Image.SCALE_DEFAULT));
        setResizable(false); // 不可改变窗口大小
        // 获取屏幕大小和当前frame的大小
        Dimension thisScreen = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension thisFrame = this.getSize();
        // 使启动窗口位于屏幕的正中心
        setLocation((thisScreen.width - thisFrame.width) / 2,
                (thisScreen.height - thisFrame.height) / 2);
        // 设置单击窗口的【关闭】按钮时将发生相应的动作
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        JMenuBar menuBar = new JMenuBar(); // 创建菜单栏
        // 创建菜单
        JMenu JM_job = new JMenu("职业管理");
        JMenuItem JMI_addjob = new JMenuItem("添加职业");
        JMI_addjob.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new JobAddFrame().setVisible(true);
            }
        });

        JMenuItem JMT_updateAndDeleteJob = new JMenuItem("更新和删除职业");
        JMT_updateAndDeleteJob.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new Job_Update_Delete().setVisible(true);
            }
        });
        JMenuItem JMT_AllJob = new JMenuItem("查看所有职业");
        JMT_AllJob.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new AllJobs().setVisible(true);
            }
        });
        JM_job.add(JMI_addjob);
        JM_job.add(JMT_updateAndDeleteJob);
        JM_job.add(JMT_AllJob);


        JMenu JM_Employer = new JMenu("用人单位管理");
        JMenuItem employerAdd = new JMenuItem("添加用人单位");
        employerAdd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                new EmployerAddFrame().setVisible(true);
            }
        });

        JMenuItem employerUpdateDelete = new JMenuItem("更新和删除用人单位");
        employerUpdateDelete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                new Employer_Update_Delete().setVisible(true);
            }
        });
        JMenuItem allemployers = new JMenuItem("查看所有用人单位");
        allemployers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AllEmployers().setVisible(true);
            }
        });
        JM_Employer.add(employerAdd);
        JM_Employer.add(employerUpdateDelete);
        JM_Employer.add(allemployers);


        JMenu JM_Seeker = new JMenu("求职者管理");
        JMenuItem SeekerUpdateDelete = new JMenuItem("求职者信息更新与删除");
        SeekerUpdateDelete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new Seeker_Update_Delete().setVisible(true);
            }
        });
        JMenuItem SeekerAdd = new JMenuItem("添加求职者");
        SeekerAdd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new SeekerAddFrame().setVisible(true);
            }
        });
        JMenuItem AllSeeker = new JMenuItem("查看所有求职者");
        AllSeeker.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AllSeekers().setVisible(true);
            }
        });
        JM_Seeker.add(SeekerAdd);
        JM_Seeker.add(SeekerUpdateDelete);
        JM_Seeker.add(AllSeeker);


        JMenu JM_category = new JMenu("职业类型管理");
        JMenuItem JMI_Add_category = new JMenuItem("增加职业类型");
        JMI_Add_category.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                new JobCategoryAddFrame().setVisible(true);
            }
        });

        JMenuItem JMI_Change_category = new JMenuItem("修改和删除职业类型");
        JMI_Change_category.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new Category_Update_Delete().setVisible(true);
            }
        });
        JMenuItem JMI_AllCategory = new JMenuItem("查看所有职业类型");
        JMI_AllCategory.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AllCategorys().setVisible(true);
            }
        });
        JM_category.add(JMI_Add_category);
        JM_category.add(JMI_Change_category);
        JM_category.add(JMI_AllCategory);


        JMenu fee_manage = new JMenu("费用管理");
        JMenu fee_employer = new JMenu("用人单位交费管理");
        JMenuItem showallfeeemployer = new JMenuItem("查看所有用人单位交费情况");
        showallfeeemployer.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new AllFeeEm().setVisible(true);
            }
        });
        JMenuItem addfeeemployer = new JMenuItem("增加用人单位交费信息");
        addfeeemployer.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new FeeEmAddFrame().setVisible(true);
            }
        });
        JMenuItem fee_Em_update_delete = new JMenuItem("修改和删除用人单位交费信息");
        fee_Em_update_delete.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new FeeEm_Update_Delete().setVisible(true);
            }
        });
        JMenuItem seeaspie = new JMenuItem("以饼图查看");
        seeaspie.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new PieTest(1).setVisible(true);
            }
        });

        JMenu fee_seeker = new JMenu("求职者交费管理");
        JMenuItem addfeeseeker = new JMenuItem("增加求职者交费信息");
        addfeeseeker.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                new FeeSeekerAddFrame().setVisible(true);
            }
        });

        JMenuItem fee_seeker_update_delete = new JMenuItem("修改和删除求职者交费信息");
        fee_seeker_update_delete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                new FeeSeeker_Update_Delete().setVisible(true);
            }
        });

        JMenuItem showallfeeseeker = new JMenuItem("查看所有求职者交费情况");
        showallfeeseeker.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AllFeeSeeker().setVisible(true);
            }
        });

        JMenuItem pie = new JMenuItem("以饼图查看");
        pie.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new PieTest(0).setVisible(true);
            }
        });

        fee_employer.add(addfeeemployer);
        fee_employer.add(fee_Em_update_delete);
        fee_employer.add(showallfeeemployer);
        fee_employer.add(seeaspie);


        fee_seeker.add(addfeeseeker);
        fee_seeker.add(fee_seeker_update_delete);
        fee_seeker.add(showallfeeseeker);
        fee_seeker.add(pie);

        fee_manage.add(fee_employer);
        fee_manage.add(fee_seeker);

        JMenu Systemanage = new JMenu("系统设置");
        JMenuItem changepwd = new JMenuItem("修改密码");
        changepwd.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new AdminChangePassword().setVisible(true);
            }
        });

        JMenuItem Addadmin = new JMenuItem("添加管理员");
        Addadmin.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AddAdminFrame().setVisible(true);
            }
        });


        JMenuItem Logout = new JMenuItem("注销登录");
        Logout.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                dispose();
                new LogInFrame().setVisible(true);
            }
        });
        Systemanage.add(changepwd);
        Systemanage.add(Addadmin);
        Systemanage.add(Logout);

        menuBar.add(JM_category);
        menuBar.add(JM_job);

        menuBar.add(JM_Employer);
        menuBar.add(JM_Seeker);
        menuBar.add(fee_manage);
        menuBar.add(Systemanage);

        this.setJMenuBar(menuBar);
    }
}
